# 91-98
#基本捕获方法
# try:
#     f = open("test/abc.txt", "r", encoding="utf-8")
# except:
#     print("出现异常了，文件不存在，将模式该为'w'模式！")
#     f = open("test/abc.txt", "w", encoding="utf-8")

# 捕获指定的异常
# try:
#     print(name)
#     # 1 / 0 # ZeroDivisionError
# except NameError as e:
#     print("出现了变量未定义的异常",e)
#     print(type(e))

# 捕获多个异常
# try:
#     # 1/0
#     print(name)
# except (NameError, ZeroDivisionError) as e:
#     print("出现了变量未定义 或者 除以0的异常错误")
#     print(e)


# 捕获所有异常
# try:
#     # print(name)
#     # 1 / 0
#     f = open("test/aaaaa.txt","r",encoding="utf-8")
#     # print("hello")
# except Exception as e:  # Exception是顶级的异常
#     f =open("test/aaaaa.txt", "w", encoding="utf-8")
#     print("出现异常了！")
# else:  # else可选，当没有异常时会执行
#     print("好高兴，没有异常！")
# finally:  # finally，无论是否出现异常，都执行
#     print("我是finally，有没有异常我都要执行！")
#     f.close()


# 异常具有传递性
def func01():
    print("这是func01开始")
    num = 1 / 0
    print("这是func01结束")


def func02():
    print("这是func02开始")
    func01()
    print("这是func02结束")


def main():
    try:
        func02()
    except Exception as e:
        print(e)

main()